
function genTodayStr(){
	var date = new Date();
	var month=(date.getMonth()+1)<10?"0"+(date.getMonth()+1):(date.getMonth()+1);
	return date.getFullYear()+"-"+formatZero(month)+"-"+formatZero(date.getDate());
}

function genLastYearStr(){
	var date = new Date();
	date.setFullYear(date.getFullYear()-1);
	return date.getFullYear()+"-"+formatZero(date.getMonth()+1)+"-"+formatZero(date.getDate());
}

function genLastMonthDayStr(){
	var date = new Date();
	var month=(date.getMonth()+1-1)<10?"0"+(date.getMonth()+1-1):(date.getMonth()+1-1);
	return date.getFullYear()+"-"+formatZero(month)+"-"+formatZero(date.getDate());
}

function dateChange(num = 1,date = false) {
	if (!date) {
		date = new Date();//没有传入值时,默认是当前日期
		date = date.getFullYear() + '-' + (date.getMonth() + 1) + '-' + date.getDate();
	}
	date += " 00:00:00";//设置为当天凌晨12点
	date = Date.parse(new Date(date))/1000;//转换为时间戳
	date += (86400) * num;//修改后的时间戳
	var newDate = new Date(parseInt(date) * 1000);//转换为时间
	return newDate.getFullYear() + '-' + (newDate.getMonth() + 1) + '-' + newDate.getDate();
}

console.log(dateChange())
console.log(dateChange(0))
console.log(dateChange(-31))

function getNowFormatDate() {
	var date = new Date();
	var seperator = "-";
	var year = date.getFullYear();
	var month = date.getMonth() + 1;
	var strDate = date.getDate();
	if (month >= 1 && month <= 9) {
		month = "0" + month;
	}
	if (strDate >= 0 && strDate <= 9) {
		strDate = "0" + strDate;
	}
	var currentdate = year + seperator + month + seperator + strDate;
	return currentdate;
}

// console.log(genLastMonthDayStr())

function genLastWeekDayStr(){
	var date = new Date();
	date.setDate(date.getDate()-6);
	return date.getFullYear()+"-"+formatZero(date.getMonth()+1)+"-"+formatZero(date.getDate());
}

function formatZero(n){
	if(n<10){
		return "0"+n;
	}else{
		return n;
	}
}
